<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <canvas id="canvas" style="border: 1px solid #aaa; display: block; margin: 50px auto;">
        当前浏览器不支持Canvas，请更换浏览器
    </canvas>
    <script>
        window.onload = function () {
            var canvas = document.getElementById("canvas");

            canvas.width = 800;
            canvas.height = 1000;

            var context = canvas.getContext("2d");

            context.fillStyle = '#058';
            context.font = 'bold 40px sans-serif';

            context.textAlign = 'left';
            context.fillText('textAlign = left', 400, 100);

            context.textAlign = 'center';
            context.fillText('textAlign = center', 400, 200);

            context.textAlign = 'right';
            context.fillText('textAlign = right', 400, 300);

            //baseline
            context.strokeStyle = '#888';
            context.moveTo(400, 0);
            context.lineTo(400, 800);
            context.stroke();
        }

    </script>
</body>
</html>